$(document).ready(function(){
var title_link_tt, meta_link_tt, cllink_link_tt, img_link_tt;
waiting_getlink_status_trangthai=function(url)
{
//alert('eee');
var list_img=[];
var defs={img:'img_status_posted_edit_tt',show_edit:'panel_posted_status_edit_img_tt',title:'title_post_status_edit_tt',
meta:'noidung_post_status_edit_tt',cllink:'link_posted_status_tt',select_image:'select_image_link_status_tt'};

var http=/^http:\/\//g;
if(url.match(http)!=null && url.match(http)!="")
{   //alert('Link Invalid');
	$('.'+defs.img).attr({src:ROOT+'public/images/loading.gif'});$('.'+defs.img).css({'padding':'40px'});
	$('.'+defs.img).show();
	//$('.loading_tag').show();
	var waiting_getlink_abort = $.ajax({
	//url:'../../application/modules/getlink/get_link_status.php',
	url:ROOT+'application/modules/getlink/get_link_status.php',
	data:{url:url,ki:'title'},
	dataType:'json',
	type:'post',
	success:function(B){
	//alert(B); return false;
	//alert(B.title);return false;
	title_link_tt = B.title;
	meta_link_tt = B.meta;
	cllink_link_tt = B.link;
	$('.'+defs.title).html(B.title);
	$('.'+defs.meta).html(B.meta);
	$('.'+defs.cllink).html(B.link);
	$('.'+defs.show_edit).slideDown("fast");
	} 
	});
	
	var waiting_getlink_abort = $.ajax({
	url:ROOT+'application/modules/getlink/get_link_status.php',
	data:{url:url,ki:'img'},
	dataType:'json',
	type:'post',
	success:function(B){
	list_img=B.img;
	img_link_tt = B.img[0];
	//alert(list_img.length);
	$('.'+defs.img).css({'padding':'0px'});
	(list_img.length>0) ?  $('.'+defs.img).attr({src:B.img[0]}) : $('.'+defs.img).hide();
	(list_img.length>0) ?  $('.'+defs.img).show() : $('.'+defs.img).hide();
	(list_img.length>0) ? $('.'+defs.select_image).show() : $('.'+defs.select_image).hide();
	//$('.loading_tag').hide();
	} 
	});
	
	//end ajax
	var index_img=0;
	$('.next_img_status_tt').click(function(){
	index_img++;
	(index_img>=list_img.length) ? index_img=0 : index_img;
	
	$('.'+defs.img).attr({src:list_img[index_img]});
	img_link_tt = list_img[index_img];
	
	});
	$('.prev_img_status_tt').click(function(){
	index_img--;
	(index_img<=0) ? index_img=list_img.length : index_img;
	$('.'+defs.img).attr({src:list_img[index_img]});
	img_link_tt = list_img[index_img];
	
	});
	}
	else {//$('.loading_tag').hide();
	waiting_getlink_abort.abort();}
},

submit_post_trangthai=function(){
	var noidung=$('.input_nd_th');
	var new_post =$('#new_post');

		$.ajax({
		url:"Posts/index/addpostuser",
	//	url:"http://localhost/hoidap/Source/Posts/index/addpostuser",
		data:{content:noidung.val(), catcha:'', catcon:'',
		meta_tile:title_link_tt, meta_image:img_link_tt, meta_link:cllink_link_tt, meta_content:meta_link_tt,
		post_title:'', post_image:'', post_type:'3'
		},

		type:'post',
		dataType:'html',
		success:function(html)
		{
			noidung.val('');
			new_post.html(html);
			new_post.attr('id', '');
			$('.panel_posted_status_edit_img_tt').hide();	
			$('.input').val('');	
			return false;			 
		}
		
		});
}



	




/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


});
